#ifndef LOGGER_H
#define LOGGER_H

#include "../../include/itlogger.h"
#include <QtSql>

struct TmLogMsg
{
    TmLogMsg() {memset(this, 0, sizeof(TmLogMsg));}
    int msgtype;
    bool bIsSign;
    int lParam;
    char szParam1[64];
    char szParam2[512];
};
typedef std::list<TmLogMsg*> TmMsgList;

class Logger : public ITLogger
{
    Q_OBJECT
public:
    static Logger* GetInstance() {static Logger __instance; return &__instance;}
public:
    Logger();
    virtual ~Logger();
    virtual TRESULT Init();
    virtual TRESULT UnInit(int nTime);
    virtual TRESULT SetFramework(ITFramework* pFrm);
    virtual TRESULT WriteLog(const char *szLog, int level);
    virtual TRESULT WriteMemory(const char *userId, int M);
    virtual TRESULT WriteUserSign(const char *userId, bool bIsSign);
    virtual TRESULT ClearUserSign();
    virtual TRESULT GetMemory();
    virtual TRESULT CollectData(int nEventId, char *userId, char *username);

public:
private:
    void writeLogger(const char *szLog, int level=0);
    QThread     m_thread;
    QMutex      m_mutex;
    TmMsgList   m_listLog;

    QFile       m_file;
    bool        m_IsOpenLog;
    QString     m_szLog;
    //
    enum __LogRecordType
    {
        Logger_min = 0,
        Logger_Log,
        Logger_UserMemory,
        Logger_UserSign,
        Logger_ClearUserSign,
        Logger_GetMemory,
        Logger_CollectData,
        Logger_max,
    };

    ITFramework     *m_pFramework;
    //
    QSqlDatabase    m_db;
    QSqlQuery       *m_dbquery;
signals:
    void sigPostTrdMsg();
private slots:
    void slotGetTrdMsg();
};


#endif // LOGGER_H
